<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="学生编号">
              <a-input placeholder="请输入学生编号" v-model="queryParam.stuId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="专业">
              <j-dict-select-tag placeholder="请选择专业" v-model="queryParam.majorId" dictCode="MAJOR,MAJOR_NAME,MAJOR_ID"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('学生信息表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text) }}</div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item v-if='record.stuStatusId==0'>
                 <a @click="upStatus(record.id,1)">更改状态</a>
              </a-menu-item>
              <a-menu-item v-if='record.stuStatusId==1'>
                 <a @click="upStatus(record.id,0)">更改状态</a>
              </a-menu-item>
              <!--就业信息-->
             <a-menu-item v-show='record.stuStatusId==1'>
              <a @click="selectEmploymenInformationByStuId(record.stuId)">就业信息</a>
            </a-menu-item>
                <!--就业维护-->
             <a-menu-item v-show='record.stuStatusId==1'>
              <a @click="selectEmploymenMaintainByStuId(record.stuId)">就业维护</a>
            </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>

        </span>

      </a-table>
    </div>

    <stu-modal ref="modalForm" @ok="modalFormOk"></stu-modal>
    <employmen-information-modal ref="modalFormEmploymenInformation" @ok="modalFormOk"></employmen-information-modal>
    <!--就业维护弹框-->
    <a-modal
      title="就业维护管理"
      :visible="visible"
      :width='width'
      :footer="null"
      :keyboard="true"
      :destroyOnClose="true"
      @cancel="handleCancel"
    >

      <!--      {{studentId}}-->
      <employmen-maintain-list ref="EmploymenMaintainList" :studentId="studentId"></employmen-maintain-list>

    </a-modal>

  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import EmploymenInformationModal from './modules/EmploymenInformationModal'
  import EmploymenMaintainList from './modules/EmploymenMaintainList'
  import StuModal from './modules/StuModal'
  import Area from '@/components/_util/Area'
  import {filterDictText, initDictOptions} from "../../../components/dict/JDictSelectUtil";
  import {getAction, httpAction} from "../../../api/manage";

  export default {
    name: 'StuList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      StuModal,
      EmploymenInformationModal,
      EmploymenMaintainList
    },
    data () {
      return {
        description: '学生信息表管理页面',
        //弹窗属性
        visible: false,
        confirmLoading: false,
        width:1200,
        studentId:"",
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'学生编号',
            align:"center",
            dataIndex: 'stuId'
          },
          {
            title:'账号',
            align:"center",
            dataIndex: 'stuAccount'
          },
          {
            title:'昵称',
            align:"center",
            dataIndex: 'stuUsername'
          },
          {
            title:'头像',
            align:"center",
            dataIndex: 'stuPhoto',
            scopedSlots: {customRender: 'imgSlot'}
          },
          {
            title:'真实姓名',
            align:"center",
            dataIndex: 'stuName'
          },
          {
            title:'现居地址',
            align:"center",
            dataIndex: 'addressId',
            scopedSlots: {customRender: 'pcaSlot'}
          },
          {
            title:'手机号',
            align:"center",
            dataIndex: 'stuPhone'
          },
          {
            title:'学历',
            align:"center",
            dataIndex: 'educationId',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              for (let i = 0; i < this.educationListDictOptions.length; i++) {
                if (text==this.educationListDictOptions[i].eduId){
                  return this.educationListDictOptions[i].eduName
                }
              }
            }
          },
          {
            title:'专业',
            align:"center",
            dataIndex: 'majorId',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              for (let i = 0; i < this.majorListDictOptions.length; i++) {
                if (text==this.majorListDictOptions[i].majorId){
                  return this.majorListDictOptions[i].majorName
                }
              }
            }
          },
          {
            title:'性别',
            align:"center",
            dataIndex: 'stuSex',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              return filterDictText(this.stuSexDictOptions, text);
            }
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'stuStatusId',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              return filterDictText(this.stuStatusDictOptions, text);
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/stu/stu/list",
          upStatusUrl:"/stu/stu/upStatus",
          delete: "/stu/stu/delete",
          deleteBatch: "/stu/stu/deleteBatch",
          exportXlsUrl: "/stu/stu/exportXls",
          importExcelUrl: "stu/stu/importExcel",
          majorListUrl:"/major/major/majorList",
          educationListUrl:"/education/education/educationList",
          selectEmploymenInformationByStuIdUrl:"stu/stu/selectEmploymenInformationByStuId"
        },
        dictOptions:{},
        pcaData:'',
        superFieldList:[],
        stuStatusDictOptions:[],
        stuSexDictOptions:[],
        majorListDictOptions:[],
        educationListDictOptions:[],
        employmenInformationByStuIdResult:{},
      }
    },
    created() {
      this.pcaData = new Area()
      console.log(this.pcaData);
      this.getSuperFieldList();
      this.majorList()
      this.educationList()
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      /*就业信息回显数据源*/
      selectEmploymenInformationByStuId(stuId){
        this.loading = true;
        httpAction(this.url.selectEmploymenInformationByStuIdUrl+"?stuId="+stuId,{},"post").then((res)=>{
          this.confirmLoading = true;
          if(res.success){
            this.employmenInformationByStuIdResult=res.result;
            this.showEmploymentInformation(this.employmenInformationByStuIdResult);
          }
        }).finally(() => {
          this.loading = false;
        })

      },
      /*显示弹窗*/
      showModal(stuId) {
        this.visible = true;
        this.studentId = stuId;
        /*JeecgListMixin.data.queryParam.stuId=this.studentId;*/
      },
      /*隐藏弹窗*/
      handleCancel(e) {
        this.visible = false;
      },


      //修改状态
      upStatus(id,newStuStatus){
        this.$http.get(this.url.upStatusUrl+'/'+id+'/'+newStuStatus).then((res)=>{
          if (res.success){
            this.$message.success('更改成功！');
            this.loadData();//页面局部刷新
          }else {
            this.$message.warning('更改失败！');
          }
        })
      },

      getPcaText(code){
        return this.pcaData.getText(code);
      },

      majorList(){
        getAction(this.url.majorListUrl).then((resp)=>{
          if (resp.success){
            this.majorListDictOptions=resp.result
          }
        })
      },
      educationList(){
        getAction(this.url.educationListUrl).then((resp)=>{
          if (resp.success){
            this.educationListDictOptions=resp.result
          }
        })
      },
      initDictConfig(){
        //初始化字典
        initDictOptions('stu_status').then((res) => {
          if (res.success) {
            this.stuStatusDictOptions = res.result;
          }
        });
        initDictOptions('sex').then((res) => {
          if (res.success) {
            this.stuSexDictOptions = res.result;
          }
        });
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'stuId',text:'学生编号',dictCode:''})
        fieldList.push({type:'string',value:'stuAccount',text:'账号',dictCode:''})
        fieldList.push({type:'string',value:'stuUsername',text:'昵称',dictCode:''})
        fieldList.push({type:'string',value:'stuPhoto',text:'头像',dictCode:''})
        fieldList.push({type:'string',value:'stuName',text:'真实姓名',dictCode:''})
        fieldList.push({type:'pca',value:'addressId',text:'现居地址'})
        fieldList.push({type:'string',value:'stuPhone',text:'手机号',dictCode:''})
        fieldList.push({type:'string',value:'educationId',text:'学历',dictCode:"EDUCATION,EDU_NAME,EDU_ID"})
        fieldList.push({type:'string',value:'majorId',text:'专业',dictCode:"MAJOR,MAJOR_NAME,MAJOR_ID"})
        fieldList.push({type:'string',value:'stuIdcard',text:'身份证',dictCode:''})
        fieldList.push({type:'int',value:'stuSex',text:'性别',dictCode:'sex'})
        fieldList.push({type:'string',value:'stuStatusId',text:'状态',dictCode:'stu_status'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>